package leetcode;

import java.util.ArrayList;

/**
 * Created by Ghost on 2014/10/7.
 */
public class Plus_one {
    public static int[] plusOne(int[] digits) {
        int lenN = digits.length;
        ArrayList<Integer> rst = new ArrayList<Integer>();
        int i = lenN-1;

        int c = (digits[i]+1)/10;
        rst.add((digits[i]+1)-c*10);
        i--;
        while(i>=0){
            int tmp = digits[i]+c;
            c = tmp/10;
            rst.add(tmp-c*10);
            i--;
        }
        if(c>0)
            rst.add(c);
        int lenR = rst.size();
        int[] rstDigits = new int[lenR];
        lenR--;
        for(Integer num: rst){
            rstDigits[lenR] = num;
            lenR--;
        }
        return rstDigits;
    }
    public static void main(String[] args){
        int[] a = plusOne(new int[]{9});
        for(int i=0;i<a.length;i++)
            System.out.print(a[i]);
    }
}
